package com.gy.sb.sbmqrabbit.utils;

import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Send {

//    private final static String QUEUE_NAME = "hello";
    
//    private final static String QUEUE1 = "Queue1";
    
    private final static String EXCHANGE = "queue1";

    public static void main(String[] argv)
            throws java.io.IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("admin");
        factory.setPassword("pwd123");
        factory.setHost("192.168.1.101");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        
        String message = "Hello World HA HA HA HA.....!";

        // 60 秒未被消费则 进入死信队列
        AMQP.BasicProperties properties = new AMQP.BasicProperties();
        properties = properties.builder().expiration(String.valueOf(10000)).build();//设置消息的过期时间为10秒
        
//        channel.queueDeclare("queue1", false, false, false, null);
        channel.basicPublish(EXCHANGE, "dlx", properties, message.getBytes());
        System.out.println(" [x] Sent '" + message + "'");
        channel.close();
        connection.close();
    }
}
